package com.ruoyi.web.controller.marry;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marry.domain.TMarryLovers;
import com.ruoyi.marry.service.ITMarryLoversService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 婚礼邀请表Controller
 *
 * @author user_marry
 * @date 2020-11-23
 */
@RestController
@RequestMapping("/marry/marryLovers")
public class TMarryLoversController extends BaseController {

    @Autowired
    private ITMarryLoversService tMarryLoversService;

    /**
     * 查询婚礼邀请表列表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryLovers:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMarryLovers tMarryLovers) {
        startPage();
        List<TMarryLovers> list = tMarryLoversService.selectTMarryLoversList(tMarryLovers);
        return getDataTable(list);
    }

    /**
     * 导出婚礼邀请表列表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryLovers:export')")
    @Log(title = "婚礼邀请表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMarryLovers tMarryLovers) {
        List<TMarryLovers> list = tMarryLoversService.selectTMarryLoversList(tMarryLovers);
        ExcelUtil<TMarryLovers> util = new ExcelUtil<TMarryLovers>(TMarryLovers.class);
        return util.exportExcel(list, "marryLovers");
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:marryLovers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tMarryLoversService.selectTMarryLoversById(id));
    }

    /**
     * 新增婚礼邀请表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryLovers:add')")
    @Log(title = "婚礼邀请表", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TMarryLovers tMarryLovers) {
        return toAjax(tMarryLoversService.insertTMarryLovers(tMarryLovers));
    }

    /**
     * 修改婚礼邀请表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryLovers:edit')")
    @Log(title = "婚礼邀请表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMarryLovers tMarryLovers) {
        return toAjax(tMarryLoversService.updateTMarryLovers(tMarryLovers));
    }

    /**
     * 删除婚礼邀请表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryLovers:remove')")
    @Log(title = "婚礼邀请表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tMarryLoversService.deleteTMarryLoversByIds(ids));
    }
}
